<template>
  <div>
    <div class="vedio-item-search">
      <input type="text" name="key" id="item-search" placeholder="失去焦点后搜索....." @blur="getData()">
      
    </div>
    <div class="vedio-items-container">
      <div
        class="vedio-item"
        v-for="v in videoList"
        :key="v.index"
        @click="playVideo(v.url,v.videoTitle)"
      >
        <div class="vedio-item-img">
          <el-image style="width: 100%; height: 160px" :src="v.fileUrl" fit="cover"></el-image>
          <div class="vedio-item-img-cover">
            <i class="el-icon-video-play"></i>
          </div>
        </div>

        <div class="vedio-item-img-title">{{v.videoTitle}}</div>

        <div class="vedio-modifed">
          <div class="vedio-item-manageName">
            <i class="el-icon-user-solid"></i>
            {{v.manageName}}
          </div>
          <span>
            <i class="el-icon-timer"></i>
            {{v.createTime}}
          </span>
        </div>
      </div>
      <div class="vedio-item" v-for="i in 3-videoList.length%3" :key="i"></div>
    </div>
  </div>
</template>
<script>
import { getVideo } from "@/api/video";
export default {
  data() {
    return {
      videoList: [],
      lengths: [],
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      var key=document.getElementById("item-search").value
      getVideo(key, 1, 100).then((res) => {
        this.videoList = res.data.list;
        this.getLengths();
      });
    },
    getLengths() {
      this.videoList.forEach((value) => {
        var audio = new Audio(value.url);
        // 元数据已加载
        audio.addEventListener("loadedmetadata", function () {
          let duration = audio.duration;
          console.log(new Date(duration));
        });
      });
    },
    playVideo(url, title) {
      this.$router.push({
        path: "/playVideo",
        query: {
          url: url,
          title: title,
        },
      });
    },
  },
};
</script>
<style>
.vedio-items-container {
  display: flex;
  flex-wrap: wrap;
  align-content: space-around;
  justify-content: space-between;
}
.vedio-item {
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-self: center;
  flex: 0 0 300px;
  margin-bottom: 50px;
}
.vedio-item-img-title {
  padding-left: 0.5rem;
  height: 2rem;
  font-size: 1rem;
  line-height: 2rem;
}
.vedio-item-manageName {
  color: rgb(160, 160, 160);
  font-size: 0.9rem;
}
.vedio-modifed > span {
  height: 1.5rem;
  font-size: 0.8rem;
  color: rgb(160, 160, 160);
}
.vedio-modifed {
  padding: 0.4rem 0.6rem;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
.vedio-item-img-cover {
  opacity: 0;
  transition: ease-in-out 0.8s;
  transition-property: width, height;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  position: absolute;
  width: 70px;
  height: 70px;
  background: rgba(0, 0, 0, 0.5);
}
.vedio-item:hover .vedio-item-img-cover {
  opacity: 1;
  width: 400px;
  height: 400px;
}
.vedio-item:hover .vedio-item-img-cover > i {
  opacity: 1;
}
.vedio-item-img-cover > i {
  opacity: 0;
  transition: 0.3s ease-in;
  align-self: center;
  font-size: 4.5rem;
  color: #fff;
}

.vedio-item-img {
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}
#item-search{
  position: relative;
  padding-left: 1rem;
  border-radius: 50px;
  width: 40%;
  height: 3rem;
  border: solid 2px #ebb563;
  transition: ease-in-out 0.3s;
  background-image: url('/assets/img/search.png');

}

#item-search:focus{ 
  border: solid 3px #ebb563;
  outline: none;
  width: 60%;
  font-size: 1.2rem;
}
.vedio-item-search{ 
  display: flex;
  justify-content: center;
  align-items: center;
  height: 11rem;
  padding: 0.5rem;
}
</style>